package live.zs.fc;

import com.aliyun.fc.runtime.Context;
import com.aliyun.fc.runtime.FunctionComputeLogger;
import com.aliyun.fc.runtime.FunctionInitializer;
import com.aliyun.fc.runtime.PojoRequestHandler;
import live.zs.fc.pojo.SimpleRequest;
import live.zs.fc.pojo.SimpleResponse;

import java.io.IOException;

/**
 * @author madison
 * @description
 * @date 2022/1/20 21:47
 */
public class InitializerAndPojoRequest implements FunctionInitializer, PojoRequestHandler<SimpleRequest, SimpleResponse> {

    @Override
    public void initialize(Context context) throws IOException {
        FunctionComputeLogger logger = context.getLogger();
        logger.debug(String.format("RequestID is %s %n", context.getRequestId()));
    }

    @Override
    public SimpleResponse handleRequest(SimpleRequest request, Context context) {
        FunctionComputeLogger logger = context.getLogger();
        logger.debug(String.format("RequestID is %s %n", context.getRequestId()));
        String message = "Hello, " + request.getFirstName() + " " + request.getLastName();
        return new SimpleResponse(message);
    }
}
